package com.txsj.scan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.txsj.scan.R;
import com.txsj.scan.bean.TagInfo;

import java.util.ArrayList;
import java.util.List;

public class UnusefulAdapter extends RecyclerView.Adapter<UnusefulAdapter.UnuseFulViewHolder> {

    private Context context;
    private List<TagInfo> tagInfoList;

    public UnusefulAdapter(Context context) {
        this.context = context;
        tagInfoList = new ArrayList<>();
    }

    public void setData(TagInfo data){
//        tagInfoList.clear();
        if (null != data){
            tagInfoList.add(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public UnuseFulViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new UnuseFulViewHolder(LayoutInflater.from(context).inflate(R.layout.item_unuseful,parent,false));
    }

    @Override
    public void onBindViewHolder(UnuseFulViewHolder holder, int position) {
        if (null != tagInfoList.get(position)){
            holder.tv_epc.setText(tagInfoList.get(position).getStrEPC());
        }
    }

    @Override
    public int getItemCount() {
        return tagInfoList.size() >0 ?tagInfoList.size():0;
    }

    public void clear() {
        tagInfoList.clear();
        notifyDataSetChanged();
    }

    public class UnuseFulViewHolder extends RecyclerView.ViewHolder{

        TextView tv_epc ;

        public UnuseFulViewHolder(View itemView) {
            super(itemView);
            tv_epc = (TextView) itemView.findViewById(R.id.tv_epc);
        }
    }
}
